<?php
/*
	[Office 515158] (C) 2009-2012 天生创想 Inc.
	$Id: mod_help 1209087 2012-01-08 08:58:28Z baiwei.jiang $
*/
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
empty($do) && $do = 'list';
if ($do == 'list') {
	//列表信息 
	$wheresql = '';
	$page = max(1, getGP('page','G','int'));
	$pagesize = $_CONFIG->config_data('pagenum');
	$offset = ($page - 1) * $pagesize;
	$url = 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'';
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."help WHERE 1 $wheresql ORDER BY id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."help WHERE 1 $wheresql ORDER BY id desc LIMIT $offset, $pagesize";
	$result = $db->fetch_all($sql);
	include_once('template/helplist.php');

}elseif ($do == 'update') {
	get_config_keytable("date_help_delete");
	$idarr = getGP('id','P','array');
	foreach ($idarr as $id) {
		$db->query("DELETE FROM ".DB_TABLEPRE."help WHERE id = '$id'");	}
	show_msg('帮助信息删除成功！', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'');

}elseif ($do == 'add') {
	if($_POST['view']!=''){
		$id = getGP('id','P','int');
		if($id!=''){
			$title = check_str(getGP('title','P'));
			$helpid = check_str(getGP('helpid','P'));
			$date = getGP('date','P');
			$contents = getGP('content','P');
			$help = array(
				'title' => $title,
				'content' => $contents,
				'helpid' => $helpid,
				'helpdate' => get_date('Y-m-d H:i:s',PHP_TIME)
			);
			update_db('help',$help, array('id' => $id));
			
		}else{
			$title = check_str(getGP('title','P'));
			$helpid = check_str(getGP('helpid','P'));
			$contents = getGP('content','P');
			$help = array(
				'title' => $title,
				'content' => $contents,
				'helpid' => $helpid,
				'helpdate' => get_date('Y-m-d H:i:s',PHP_TIME)
			);
			insert_db('help',$help);
		}
		show_msg('帮助信息操作成功！', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'');
	}else{
		$id = getGP('id','G','int');
		
		if($id!=''){
			$user = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."help  WHERE id = '$id'");
			get_config_keytable('date_help_edit');
			$date=$user['date'];
			$_title['name']='编辑';
		}else{ 
			get_config_keytable('date_help_Increase');
			$date=get_date('Y-m-d',PHP_TIME);
			$user['type']='1';
			$_title['name']='发布';
		}
		include_once('template/helpadd.php');
	}
}elseif ($do == 'views') {
		$id = getGP('id','G','int');
			if($id!=''){
				$help = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."help  WHERE id = '$id'");
				$_title['name']='信息浏览';
			}
		include_once('template/helpviews.php');
}
?>